package com.zx.controller;

import com.zx.config.AsyncTask;
import com.zx.config.AsyncTaskManager;
import com.zx.service.IAsyncGoodsService;
import com.zx.vo.GoodsInfo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.UUID;

@RestController
@RequestMapping("/async")
public class AsyncGoodsController {

    @Resource
    private AsyncTaskManager taskManager;

    @Resource
    private IAsyncGoodsService asyncGoodsService;

    @PostMapping("/import-goods")
    public String importGoods(@RequestBody List<GoodsInfo> goodsInfos){
        AsyncTask asyncTask = taskManager.submit(goodsInfos);
        return asyncTask.getId();
    }

    /*@PostMapping("/import-goods")
    public String importGoods(@RequestBody List<GoodsInfo> goodsInfos){
        asyncGoodsService.asyncImportGoods(goodsInfos,"2");
        return "success";
    }*/
    @GetMapping("/get-task-by-id/{taskId}")
    public AsyncTask getTaskInfoById(@PathVariable("taskId") String taskId){
        return taskManager.getTask(taskId);
    }
}
